//AUTHOR: CADENCE WILLSE
//NAME: Centralization and Subnational Capacity Data Analysis
//CREATED: APRIL 2018
//LAST UPDATED: 06/15/2021


//Set workspace

cd "/Users/willsec/Documents/Centralization and Subnational Capacity/ReplicationFile"
use "NCES Gov Capacity and NCCS Orgs By Year.dta", clear

*****NATIONAL ANALYSIS*****

//Table 4: Administrative and Technical Capacity ITSA, 1997-2015

use  "NCES Gov Capacity and NCCS Orgs By Year.dta", replace
tsset year
itsa admin_weighted, single trperiod(2003 2010) lag(1) fig posttrend //Figure 1

eststo national_admin

use  "NCES Gov Capacity and NCCS Orgs By Year.dta", replace
tsset year
itsa instruction_weighted, single trperiod(2003 2010) lag(1) fig posttrend //Figure 2

eststo national_instruction

estout national_admin national_instruction, cells(b(star fmt(%9.3f)) se(par))                ///
        stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))      ///
        legend label collabels(none) varlabels(_cons Constant)  




*****SUBGROUP ANALYSIS*****

use "NCES Capacity and SAIPE County 9715", clear

// divide counties into income quintiles by childhood poverty levels (percent of the population aged 5-17 living in poverty). 
xtile pov=Pov_517Pct, n(5)
drop if missing(pov)
//(1 observation deleted)

sum Pov_517Pct if pov==1 //  9.3
sum Pov_517Pct if pov==5 // 32.8

//collapse for subgroup poverty quintile category
collapse (sum) teacher libsup libspe leaadm schadm leasup schsup corsup member, by(year pov)

gen admin_county =  leaadm + schadm + leasup + schsup 
gen admin_weighted_county = (admin_county/member)*100
gen instruction_county = (corsup/member)*100

save "NCES Capacity Data and Saipe County Subgroup 9715.dta", replace


//Table 5: Administrative Capacity in Low Poverty and High Poverty Counties ITSA, 1997-2015

//Low Poverty
use "NCES Capacity Data and Saipe County Subgroup 9715.dta", clear
keep if pov==1 
tsset year 
itsa admin_weighted_county, single trperiod(2003 2010) lag(1) fig posttrend //Figure 3
eststo lowpov_admin

//High Poverty
use "NCES Capacity Data and Saipe County Subgroup 9715.dta", clear
keep if pov==5 
tsset year 
itsa admin_weighted_county, single trperiod(2003 2010) lag(1) fig posttrend //Figure 4
eststo highpov_admin

estout lowpov_admin highpov_admin, cells(b(star fmt(%9.3f)) se(par))                ///
        stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))      ///
        legend label collabels(none) varlabels(_cons Constant)

//Table 6: Technical Capacity in Low Poverty and High Poverty Counties ITSA, 1997-2015

//Low Poverty
use "NCES Capacity Data and Saipe County Subgroup 9715.dta", clear
keep if pov==1 
tsset year 
itsa instruction_county, single trperiod(2003 2010) lag(1) fig posttrend //Figure 5
eststo lowpov_instruction

//High Poverty
use "NCES Capacity Data and Saipe County Subgroup 9715.dta", clear
keep if pov==5 
tsset year 
itsa instruction_county, single trperiod(2003 2010) lag(1) fig posttrend //Figure 6
eststo highpov_instruction

estout lowpov_instruction highpov_instruction, cells(b(star fmt(%9.3f)) se(par))                ///
        stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))      ///
        legend label collabels(none) varlabels(_cons Constant)



//Robustness checks


//Figure 7: State Administrative Capacity ITSA, 1997-2015

use "StateOtherEducationData.dta", clear
collapse (sum) othereducationemployees, by(year)
merge 1:1 year using "NCES Gov Capacity and NCCS Orgs By Year.dta"

save "StateOtherEducationData_9715.dta", replace

use "StateOtherEducationData_9715.dta", clear
gen othered_weighted = (othereducationemployees/member)*100
tsset year
itsa othered_weighted, single trperiod(2003 2010) lag(1) fig posttrend //Figure 7

eststo state

estout state, cells(b(star fmt(%9.3f)) se(par))                ///
        stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))      ///
        legend label collabels(none) varlabels(_cons Constant)


//Figure 8: Nongovernmental Capacity ITSA, 1997-2015
use  "NCES Gov Capacity and NCCS Orgs By Year.dta", replace
tsset year
itsa service_weighted, single trperiod(2003 2010) lag(1) fig posttrend //Figure 8


eststo ngo

estout ngo, cells(b(star fmt(%9.3f)) se(par))                ///
        stats(r2_a N, fmt(%9.3f %9.0g) labels(R-squared))      ///
        legend label collabels(none) varlabels(_cons Constant)











